;;; This file is part of guix-bavier.git
;;; Copyright © 2020 Eric Bavier <bavier@posteo.net>
;;; License: GPLv3+

(define-module (bavier packages android)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix bzr-download)
  #:use-module (guix build-system cmake)
  #:use-module (bavier packages systemd)
  #:use-module (gnu packages)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages check)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages maths)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages protobuf)
  #:use-module (gnu packages python)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages virtualization)
  #:use-module (gnu packages xml)
  #:use-module ((guix licenses) #:prefix license:))

(define-public properties-cpp
  (let ((bzr-revision "17"))
    (package
      (name "properties-cpp")
      (version "0.0.1")
      (source (origin
                (method bzr-fetch)
                (uri (bzr-reference
                      (url "lp:properties-cpp")
                      (revision bzr-revision)))
                (file-name (string-append name "-" version "-checkout"))
                (sha256
                 (base32
                  "1dj3imffbl8fqf3nsymcgv92k0h5mp0df4xnxbr6zrjqafi7h89a"))
                (patches (search-patches
                          "bavier/patches/properties-cpp-findgtest.patch"))))
      (build-system cmake-build-system)
      (inputs
       `(("gtest/gmock" ,googletest)))
      (arguments
       `(#:configure-flags (list
                            "-DCMAKE_BUILD_TYPE=Release"
                            (string-append "-DGTEST_INSTALL_DIR="
                                           (assoc-ref %build-inputs "gtest/gmock")
                                           "/include")
                            (string-append "-DGMOCK_INSTALL_DIR="
                                           (assoc-ref %build-inputs "gtest/gmock")
                                           "/include"))))
      (home-page "https://launchpad.net/properties-cpp")
      (synopsis "Properties and signals library for C++")
      (description "process-cpp is a simple header-only implementation of
properties and signals. It is meant to be used for developing low-level system
services. Its main features include:

@itemize
@item Thread-safe signal invocation and observer mgmt.
@item The ability to dispatch signal invocations via arbitrary event loops.
@item Typed properties with an in-place update mechanism that avoids unneccessary deep copies.
@item Well tested and documented.
@end itemize")
      (license license:gpl3))))

(define-public anbox
  (let ((commit "bfbb2b1a20f79cc7bcaac539538c8ef441310ed5") ; Latest as of Fri 18 Sep 2020 01:30:51 AM UTC
        (revision "1"))
    (package
     (name "anbox")
     (version (git-version "0" revision commit))
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/anbox/anbox.git")
                    (commit commit)
                    (recursive? #t))) ; For external/sdbus-cpp and external/cpu_features
              (file-name (git-file-name name version))
              (sha256
               (base32
                "1dnimvzaqynjcsp7bp1nkrfg5rmm57lzpcyp797dksa9qibb1vkq"))
              (patches (search-patches
                        "bavier/patches/anbox-backward-cpp-binutils-2.34.patch"))))
     (build-system cmake-build-system)
     (native-inputs
      `(("pkg-config" ,pkg-config)
        ("python2" ,python-2)))
     (inputs
      `(("dbus" ,dbus)
        ("boost" ,boost)
        ("expat" ,expat)
        ("glm" ,glm)
        ("googletest" ,googletest)
        ("libcap" ,libcap)
        ("libiberty" ,libiberty)
        ("libsystemd" ,systemd)
        ("mesa" ,mesa)
        ("sdl2" ,(sdl-union (list sdl2 sdl2-image)))
        ("properties-cpp" ,properties-cpp)
        ("protobuf" ,protobuf)
        ("lxc" ,lxc)))
     (arguments
      `(#:configure-flags
        (list (string-append "-DANBOX_VERSION=" ,version)
              "-DWerror:BOOL=OFF")
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'patch-tests
            (lambda _
              (substitute* "external/android-emugl/shared/emugl/common/CMakeLists.txt"
                ((".*unittest.*") ""))
              #t)))))
     (home-page "https://anbox.io/")
     (synopsis "Android in a box")
     (description "Anbox uses Linux namespaces (user, pid, uts, net, mount, ipc)
to run a full Android system in a container and provide Android applications
on any GNU/Linux-based platform.")
     (license (list license:gpl3+
                    license:sgifreeb2.0
                    license:asl2.0
                    license:x11
                    ;; external/process-cpp-minimal:
                    license:gpl3
                    ;; external/sdbus-cpp
                    license:lgpl2.1+
                    ;; external/cpu_features
                    license:asl2.0)))))
